package Lian01;

public class ZiFuChuan {
    public static void main(String[] args) {
        String str1 = "hello";
        String str2 = "中国";

        System.out.println(str1);
        System.out.println(str2.length());
        System.out.println(str2.charAt(1));  //字符串的提取
        System.out.println(str1+"\t"+str2);  //字符串的连接
        System.out.println(str1.equals(str2)); //判断字符串是否相等
        System.out.println("中国".equals(str2));

        String name = "tom";
        String name1 = "Tom";
        System.out.println(name.equals(name1));  //判断相等分大小写
        System.out.println(name.equalsIgnoreCase(name1)); //判断相等不分大小写

        String strNull ;
        String strEmpty = "";
        System.out.println(name!=null&&(!"".equals(name)));  //字符串的普遍判断方式
        System.out.println(strEmpty!=null&&(!"".equals(name)));


        //字符串的提取方法
        String strHello = "Hello World";
        System.out.println(strHello.substring(0,5));
        System.out.println(strHello.substring(3,5));
        System.out.println(strHello.substring(2));
        System.out.println(strHello.substring(0,strHello.length()));
        //字符串的转换
        System.out.println(strHello.indexOf("o"));
        System.out.println(strHello.lastIndexOf("o"));
        int index = strHello.lastIndexOf("o");
        String strSub = strHello.substring(0,index);
        String strSub1 =strHello.substring(8,strHello.length());
        String res = strSub+ "0"+strSub1;
        System.out.println(res);
        //以上转换太麻烦 用replace
        res = strHello.replace("o","a");
        System.out.println(res);

        //构建字符串关于StringBuilder类的用法
        StringBuilder stringBuilder = new StringBuilder();
    }
}
